package com.yanghui.dtracing.core.opentracing;

import com.yanghui.dtracing.core.config.AgentConfig;
import com.yanghui.dtracing.core.opentracing.sampler.SamplerProperties;

public class Tracing {

    private static DTracer instance;

    public static DTracer getTracer(){
        return instance;
    }

    public static String getTraceId(){
        if(null == instance){
            return null;
        }
        if(null == instance.activeSpan()){
            return null;
        }
        return instance.activeSpan().context().toTraceId();
    }

    public static synchronized DTracer init(AgentConfig config){
        if(null != instance){
            return instance;
        }
        instance = DTracer.builder(config.getServiceName())
                .register()
                .reporter()
                .sampler(new SamplerProperties())
                .build();
        return instance;
    }
}
